//
//  MainViewController.swift
//  weibo1
//
//  Created by Apple on 15/11/26.
//  Copyright © 2015年 Apple. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {

    let maintabbar = MainTabBar()
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
     
        //通过KVC 改变tabbar的身份
        setValue(maintabbar, forKey: "tabBar")
        //验证tabbar是不是自定义的
//        print(tabBar.classForCoder)
        //为按钮添加点击事件
        maintabbar.plasBut.addTarget(self, action: "plasButDidClick", forControlEvents: .TouchUpInside)
        
        addChildViewControllers()
        
    }
    //MARK: 按钮的点击事件
  @objc  private func plasButDidClick()
    {
        print("加号按钮被点击了")
        //跳转到发布微博的页面
        let sendVC = CompseViewController()
        
        let nav = UINavigationController(rootViewController: sendVC)
        presentViewController(nav, animated: true, completion: nil)
    }
    
    
   //添加tabbar
    private func addChildViewControllers() {
   
        addChildViewController(HomeTableViewController(), title: "首页", imageNmae: "tabbar_home")
        addChildViewController(MessageTableViewController(), title: "消息", imageNmae: "tabbar_message_center")
        addChildViewController(DiscoverTableViewController(), title: "发现", imageNmae: "tabbar_discover")
        addChildViewController(ProfileTableViewController(), title: "我", imageNmae: "tabbar_profile")
    }
    
    
  
    private func addChildViewController(vc :UIViewController,title :String, imageNmae :String) {
        
        let nav = UINavigationController(rootViewController: vc)
        
        vc.title = title
        vc.tabBarItem.image = UIImage(named: imageNmae)
        addChildViewController(nav)
    }

}
